﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using BaseEntities;

namespace DataAccess
{
    public class CheckBalanceAccess
    {
        public decimal GetBalalance(string CardNo)
        {
                SqlConnection conn = DBConnect.GetConnection();
                SqlCommand cmd = new SqlCommand();
                cmd.CommandText = "SP_GetBalanceAccount";
                cmd.Connection = conn;
                conn.Open();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@CardNo", SqlDbType.NVarChar, 16).Value = CardNo;
                SqlDataAdapter da = new SqlDataAdapter();
                DataTable dt = new DataTable();
                da.SelectCommand = cmd;
                da.Fill(dt);
                return decimal.Parse(dt.Rows[0][0].ToString());
        }

        public Account GetAccountCb(string CardNo)
        {
            Account account=new Account();
            SqlConnection conn = DBConnect.GetConnection();
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "SP_GetAccount";
            cmd.Connection = conn;
            conn.Open();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@CardNo", SqlDbType.NVarChar, 16).Value = CardNo;
            SqlDataAdapter da = new SqlDataAdapter();
            DataTable dt = new DataTable();
            da.SelectCommand = cmd;
            da.Fill(dt);
            account.AccountID = Int32.Parse(dt.Rows[0][0].ToString());
            account.Balance = decimal.Parse(dt.Rows[0][1].ToString());
            return account;
        }
    }
}
